package com.java1234.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.java1234.model.animal;
import com.java1234.model.animaled;

public class animaledDao {

	public int add(Connection con,String t,String p)throws Exception{
		String sql="insert into db_book.dbo.t_animaled values(?,?)";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, t);
		pstmt.setInt(2, Integer.valueOf(p));
		return pstmt.executeUpdate();
	}
	public List<animaled> find(Connection con)throws Exception{
		List<animaled> animalList = new ArrayList<animaled>();
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sq = "select * from db_book.dbo.view_animaled";
		pstmt = con.prepareStatement(sq);
		rs=pstmt.executeQuery();
		while(rs.next()) {
			animalList.add(new animaled(rs.getString(1),rs.getString(2),rs.getInt(3)));
		}
		return animalList;
	}
	
}
